package com.study.file.service;

import com.study.common.entity.User;
import com.study.file.dao.FileDao;
import com.study.file.entity.Entity;
import com.study.main.entity.Information;
import com.study.main.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

@Repository(value = "saveService")
public class SaveServiceImp extends PoiServiceImp implements SaveService {
    @Autowired
    @Qualifier(value = "fileDao")
    private FileDao fileDao;

    public void saveMyDate(String name) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        System.out.println("执行开始储存数据");
        // TODO Auto-generated method stub
        List<Entity> list = new ArrayList<Entity>();
        list = getExcelData(name);
        int i = 0;
        for (Entity entity : list) {
            if (fileDao.findByAll(entity.getUser()) == null) {
                fileDao.add(entity.getUser());
            }
            User user = fileDao.findByAll(entity.getUser());
            Information information;
            information = entity.getInformation();
            information.setUserId(user.getUserId());
            fileDao.add(information);
        }
    }

}
